home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / print / ServiceDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  12.4 KB  |  445 lines

  1. package sun.print;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dialog;
  7. import java.awt.FlowLayout;
  8. import java.awt.Frame;
  9. import java.awt.GraphicsConfiguration;
  10. import java.awt.GridBagConstraints;
  11. import java.awt.GridBagLayout;
  12. import java.awt.Insets;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.io.File;
  16. import java.net.URI;
  17. import java.net.URISyntaxException;
  18. import java.net.URL;
  19. import java.security.AccessController;
  20. import java.util.MissingResourceException;
  21. import java.util.ResourceBundle;
  22. import javax.print.DocFlavor;
  23. import javax.print.PrintService;
  24. import javax.print.attribute.HashPrintRequestAttributeSet;
  25. import javax.print.attribute.PrintRequestAttributeSet;
  26. import javax.print.attribute.standard.Destination;
  27. import javax.swing.AbstractButton;
  28. import javax.swing.ActionMap;
  29. import javax.swing.ButtonGroup;
  30. import javax.swing.InputMap;
  31. import javax.swing.JButton;
  32. import javax.swing.JCheckBox;
  33. import javax.swing.JDialog;
  34. import javax.swing.JOptionPane;
  35. import javax.swing.JPanel;
  36. import javax.swing.JRadioButton;
  37. import javax.swing.JTabbedPane;
  38. import javax.swing.KeyStroke;
  39. import javax.swing.border.EmptyBorder;
  40.  
  41. public class ServiceDialog extends JDialog implements ActionListener {
  42.    public static final int WAITING = 0;
  43.    public static final int APPROVE = 1;
  44.    public static final int CANCEL = 2;
  45.    private static final String strBundle = "sun.print.resources.serviceui";
  46.    private static final Insets panelInsets = new Insets(6, 6, 6, 6);
  47.    private static final Insets compInsets = new Insets(3, 6, 3, 6);
  48.    private static ResourceBundle messageRB;
  49.    private JTabbedPane tpTabs;
  50.    private JButton btnCancel;
  51.    private JButton btnApprove;
  52.    private PrintService[] services;
  53.    private int defaultServiceIndex;
  54.    private PrintRequestAttributeSet asOriginal;
  55.    private HashPrintRequestAttributeSet asCurrent;
  56.    private PrintService psCurrent;
  57.    private DocFlavor docFlavor;
  58.    private int status;
  59.    private ValidatingFileChooser jfc;
  60.    private GeneralPanel pnlGeneral;
  61.    private PageSetupPanel pnlPageSetup;
  62.    private AppearancePanel pnlAppearance;
  63.    private boolean isAWT = false;
  64.  
  65.    public ServiceDialog(GraphicsConfiguration var1, int var2, int var3, PrintService[] var4, int var5, DocFlavor var6, PrintRequestAttributeSet var7, Dialog var8) {
  66.       super(var8, getMsg("dialog.printtitle"), true, var1);
  67.       this.initPrintDialog(var2, var3, var4, var5, var6, var7);
  68.    }
  69.  
  70.    public ServiceDialog(GraphicsConfiguration var1, int var2, int var3, PrintService[] var4, int var5, DocFlavor var6, PrintRequestAttributeSet var7, Frame var8) {
  71.       super(var8, getMsg("dialog.printtitle"), true, var1);
  72.       this.initPrintDialog(var2, var3, var4, var5, var6, var7);
  73.    }
  74.  
  75.    void initPrintDialog(int var1, int var2, PrintService[] var3, int var4, DocFlavor var5, PrintRequestAttributeSet var6) {
  76.       this.services = var3;
  77.       this.defaultServiceIndex = var4;
  78.       this.asOriginal = var6;
  79.       this.asCurrent = new HashPrintRequestAttributeSet(var6);
  80.       this.psCurrent = var3[var4];
  81.       this.docFlavor = var5;
  82.       SunPageSelection var7 = (SunPageSelection)var6.get(SunPageSelection.class);
  83.       if (var7 != null) {
  84.          this.isAWT = true;
  85.       }
  86.  
  87.       Container var8 = this.getContentPane();
  88.       var8.setLayout(new BorderLayout());
  89.       this.tpTabs = new JTabbedPane();
  90.       this.tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));
  91.       String var9 = getMsg("tab.general");
  92.       int var10 = getVKMnemonic("tab.general");
  93.       this.pnlGeneral = new GeneralPanel(this);
  94.       this.tpTabs.add(var9, this.pnlGeneral);
  95.       this.tpTabs.setMnemonicAt(0, var10);
  96.       String var11 = getMsg("tab.pagesetup");
  97.       int var12 = getVKMnemonic("tab.pagesetup");
  98.       this.pnlPageSetup = new PageSetupPanel(this);
  99.       this.tpTabs.add(var11, this.pnlPageSetup);
  100.       this.tpTabs.setMnemonicAt(1, var12);
  101.       String var13 = getMsg("tab.appearance");
  102.       int var14 = getVKMnemonic("tab.appearance");
  103.       this.pnlAppearance = new AppearancePanel(this);
  104.       this.tpTabs.add(var13, this.pnlAppearance);
  105.       this.tpTabs.setMnemonicAt(2, var14);
  106.       var8.add(this.tpTabs, "Center");
  107.       this.updatePanels();
  108.       JPanel var15 = new JPanel(new FlowLayout(4));
  109.       this.btnApprove = createExitButton("button.print", this);
  110.       var15.add(this.btnApprove);
  111.       this.getRootPane().setDefaultButton(this.btnApprove);
  112.       this.btnCancel = createExitButton("button.cancel", this);
  113.       this.handleEscKey(this.btnCancel);
  114.       var15.add(this.btnCancel);
  115.       var8.add(var15, "South");
  116.       this.addWindowListener(new 1(this));
  117.       this.getAccessibleContext().setAccessibleDescription(getMsg("dialog.printtitle"));
  118.       this.setResizable(false);
  119.       this.setLocation(var1, var2);
  120.       this.pack();
  121.    }
  122.  
  123.    public ServiceDialog(GraphicsConfiguration var1, int var2, int var3, PrintService var4, DocFlavor var5, PrintRequestAttributeSet var6, Dialog var7) {
  124.       super(var7, getMsg("dialog.pstitle"), true, var1);
  125.       this.initPageDialog(var2, var3, var4, var5, var6);
  126.    }
  127.  
  128.    public ServiceDialog(GraphicsConfiguration var1, int var2, int var3, PrintService var4, DocFlavor var5, PrintRequestAttributeSet var6, Frame var7) {
  129.       super(var7, getMsg("dialog.pstitle"), true, var1);
  130.       this.initPageDialog(var2, var3, var4, var5, var6);
  131.    }
  132.  
  133.    void initPageDialog(int var1, int var2, PrintService var3, DocFlavor var4, PrintRequestAttributeSet var5) {
  134.       this.psCurrent = var3;
  135.       this.docFlavor = var4;
  136.       this.asOriginal = var5;
  137.       this.asCurrent = new HashPrintRequestAttributeSet(var5);
  138.       Container var6 = this.getContentPane();
  139.       var6.setLayout(new BorderLayout());
  140.       this.pnlPageSetup = new PageSetupPanel(this);
  141.       var6.add(this.pnlPageSetup, "Center");
  142.       this.pnlPageSetup.updateInfo();
  143.       JPanel var7 = new JPanel(new FlowLayout(4));
  144.       this.btnApprove = createExitButton("button.ok", this);
  145.       var7.add(this.btnApprove);
  146.       this.getRootPane().setDefaultButton(this.btnApprove);
  147.       this.btnCancel = createExitButton("button.cancel", this);
  148.       this.handleEscKey(this.btnCancel);
  149.       var7.add(this.btnCancel);
  150.       var6.add(var7, "South");
  151.       this.addWindowListener(new 2(this));
  152.       this.getAccessibleContext().setAccessibleDescription(getMsg("dialog.pstitle"));
  153.       this.setResizable(false);
  154.       this.setLocation(var1, var2);
  155.       this.pack();
  156.    }
  157.  
  158.    private void handleEscKey(JButton var1) {
  159.       3 var2 = new 3(this);
  160.       KeyStroke var3 = KeyStroke.getKeyStroke('\u001b', false);
  161.       InputMap var4 = var1.getInputMap(2);
  162.       ActionMap var5 = var1.getActionMap();
  163.       if (var4 != null && var5 != null) {
  164.          var4.put(var3, "cancel");
  165.          var5.put("cancel", var2);
  166.       }
  167.  
  168.    }
  169.  
  170.    public int getStatus() {
  171.       return this.status;
  172.    }
  173.  
  174.    public PrintRequestAttributeSet getAttributes() {
  175.       return (PrintRequestAttributeSet)(this.status == 1 ? this.asCurrent : this.asOriginal);
  176.    }
  177.  
  178.    public PrintService getPrintService() {
  179.       return this.status == 1 ? this.psCurrent : null;
  180.    }
  181.  
  182.    public void dispose(int var1) {
  183.       this.status = var1;
  184.       super.dispose();
  185.    }
  186.  
  187.    public void actionPerformed(ActionEvent var1) {
  188.       Object var2 = var1.getSource();
  189.       boolean var3 = false;
  190.       if (var2 == this.btnApprove) {
  191.          var3 = true;
  192.          if (this.pnlGeneral != null) {
  193.             if (this.pnlGeneral.isPrintToFileRequested()) {
  194.                var3 = this.showFileChooser();
  195.             } else {
  196.                this.asCurrent.remove(Destination.class);
  197.             }
  198.          }
  199.       }
  200.  
  201.       this.dispose(var3 ? 1 : 2);
  202.    }
  203.  
  204.    private boolean showFileChooser() {
  205.       Class var1 = Destination.class;
  206.       Destination var2 = (Destination)this.asCurrent.get(var1);
  207.       if (var2 == null) {
  208.          var2 = (Destination)this.asOriginal.get(var1);
  209.          if (var2 == null) {
  210.             var2 = (Destination)this.psCurrent.getDefaultAttributeValue(var1);
  211.             if (var2 == null) {
  212.                try {
  213.                   var2 = new Destination(new URI("file:out.prn"));
  214.                } catch (URISyntaxException var9) {
  215.                }
  216.             }
  217.          }
  218.       }
  219.  
  220.       File var3;
  221.       if (var2 != null) {
  222.          try {
  223.             var3 = new File(var2.getURI());
  224.          } catch (Exception var8) {
  225.             var3 = new File("out.prn");
  226.          }
  227.       } else {
  228.          var3 = new File("out.prn");
  229.       }
  230.  
  231.       ValidatingFileChooser var4 = new ValidatingFileChooser(this, (1)null);
  232.       var4.setApproveButtonText(getMsg("button.ok"));
  233.       var4.setDialogTitle(getMsg("dialog.printtofile"));
  234.       var4.setSelectedFile(var3);
  235.       int var5 = var4.showDialog(this, (String)null);
  236.       if (var5 == 0) {
  237.          var3 = var4.getSelectedFile();
  238.  
  239.          try {
  240.             this.asCurrent.add(new Destination(var3.toURI()));
  241.          } catch (Exception var7) {
  242.             this.asCurrent.remove(var1);
  243.          }
  244.       } else {
  245.          this.asCurrent.remove(var1);
  246.       }
  247.  
  248.       return var5 == 0;
  249.    }
  250.  
  251.    private void updatePanels() {
  252.       this.pnlGeneral.updateInfo();
  253.       this.pnlPageSetup.updateInfo();
  254.       this.pnlAppearance.updateInfo();
  255.    }
  256.  
  257.    public static void initResource() {
  258.       AccessController.doPrivileged(new 4());
  259.    }
  260.  
  261.    public static String getMsg(String var0) {
  262.       try {
  263.          return messageRB.getString(var0);
  264.       } catch (MissingResourceException var2) {
  265.          throw new Error("Fatal: Resource for ServiceUI is broken; there is no " + var0 + " key in resource");
  266.       }
  267.    }
  268.  
  269.    private static char getMnemonic(String var0) {
  270.       String var1 = getMsg(var0 + ".mnemonic");
  271.       return var1 != null && var1.length() > 0 ? var1.charAt(0) : '\u0000';
  272.    }
  273.  
  274.    private static int getVKMnemonic(String var0) {
  275.       String var1 = getMsg(var0 + ".vkMnemonic");
  276.       if (var1 != null && var1.length() > 0) {
  277.          try {
  278.             return Integer.parseInt(var1);
  279.          } catch (NumberFormatException var3) {
  280.          }
  281.       }
  282.  
  283.       return 0;
  284.    }
  285.  
  286.    private static URL getImageResource(String var0) {
  287.       URL var1 = (URL)AccessController.doPrivileged(new 5(var0));
  288.       if (var1 == null) {
  289.          throw new Error("Fatal: Resource for ServiceUI is broken; there is no " + var0 + " key in resource");
  290.       } else {
  291.          return var1;
  292.       }
  293.    }
  294.  
  295.    private static JButton createButton(String var0, ActionListener var1) {
  296.       JButton var2 = new JButton(getMsg(var0));
  297.       var2.setMnemonic(getMnemonic(var0));
  298.       var2.addActionListener(var1);
  299.       return var2;
  300.    }
  301.  
  302.    private static JButton createExitButton(String var0, ActionListener var1) {
  303.       String var2 = getMsg(var0);
  304.       JButton var3 = new JButton(var2);
  305.       var3.addActionListener(var1);
  306.       var3.getAccessibleContext().setAccessibleDescription(var2);
  307.       return var3;
  308.    }
  309.  
  310.    private static JCheckBox createCheckBox(String var0, ActionListener var1) {
  311.       JCheckBox var2 = new JCheckBox(getMsg(var0));
  312.       var2.setMnemonic(getMnemonic(var0));
  313.       var2.addActionListener(var1);
  314.       return var2;
  315.    }
  316.  
  317.    private static JRadioButton createRadioButton(String var0, ActionListener var1) {
  318.       JRadioButton var2 = new JRadioButton(getMsg(var0));
  319.       var2.setMnemonic(getMnemonic(var0));
  320.       var2.addActionListener(var1);
  321.       return var2;
  322.    }
  323.  
  324.    public static void showNoPrintService(GraphicsConfiguration var0) {
  325.       Frame var1 = new Frame(var0);
  326.       JOptionPane.showMessageDialog(var1, getMsg("dialog.noprintermsg"));
  327.       var1.dispose();
  328.    }
  329.  
  330.    private static void addToGB(Component var0, Container var1, GridBagLayout var2, GridBagConstraints var3) {
  331.       var2.setConstraints(var0, var3);
  332.       var1.add(var0);
  333.    }
  334.  
  335.    private static void addToBG(AbstractButton var0, Container var1, ButtonGroup var2) {
  336.       var2.add(var0);
  337.       var1.add(var0);
  338.    }
  339.  
  340.    // $FF: synthetic method
  341.    static ResourceBundle access$102(ResourceBundle var0) {
  342.       messageRB = var0;
  343.       return var0;
  344.    }
  345.  
  346.    // $FF: synthetic method
  347.    static Insets access$200() {
  348.       return panelInsets;
  349.    }
  350.  
  351.    // $FF: synthetic method
  352.    static void access$300(Component var0, Container var1, GridBagLayout var2, GridBagConstraints var3) {
  353.       addToGB(var0, var1, var2, var3);
  354.    }
  355.  
  356.    // $FF: synthetic method
  357.    static PrintService access$400(ServiceDialog var0) {
  358.       return var0.psCurrent;
  359.    }
  360.  
  361.    // $FF: synthetic method
  362.    static PrintService[] access$500(ServiceDialog var0) {
  363.       return var0.services;
  364.    }
  365.  
  366.    // $FF: synthetic method
  367.    static int access$600(ServiceDialog var0) {
  368.       return var0.defaultServiceIndex;
  369.    }
  370.  
  371.    // $FF: synthetic method
  372.    static Insets access$700() {
  373.       return compInsets;
  374.    }
  375.  
  376.    // $FF: synthetic method
  377.    static char access$800(String var0) {
  378.       return getMnemonic(var0);
  379.    }
  380.  
  381.    // $FF: synthetic method
  382.    static JButton access$900(String var0, ActionListener var1) {
  383.       return createButton(var0, var1);
  384.    }
  385.  
  386.    // $FF: synthetic method
  387.    static JCheckBox access$1000(String var0, ActionListener var1) {
  388.       return createCheckBox(var0, var1);
  389.    }
  390.  
  391.    // $FF: synthetic method
  392.    static PrintService access$402(ServiceDialog var0, PrintService var1) {
  393.       return var0.psCurrent = var1;
  394.    }
  395.  
  396.    // $FF: synthetic method
  397.    static PrintRequestAttributeSet access$1100(ServiceDialog var0) {
  398.       return var0.asOriginal;
  399.    }
  400.  
  401.    // $FF: synthetic method
  402.    static HashPrintRequestAttributeSet access$1200(ServiceDialog var0) {
  403.       return var0.asCurrent;
  404.    }
  405.  
  406.    // $FF: synthetic method
  407.    static void access$1300(ServiceDialog var0) {
  408.       var0.updatePanels();
  409.    }
  410.  
  411.    // $FF: synthetic method
  412.    static JRadioButton access$1400(String var0, ActionListener var1) {
  413.       return createRadioButton(var0, var1);
  414.    }
  415.  
  416.    // $FF: synthetic method
  417.    static boolean access$1500(ServiceDialog var0) {
  418.       return var0.isAWT;
  419.    }
  420.  
  421.    // $FF: synthetic method
  422.    static DocFlavor access$1600(ServiceDialog var0) {
  423.       return var0.docFlavor;
  424.    }
  425.  
  426.    // $FF: synthetic method
  427.    static ResourceBundle access$100() {
  428.       return messageRB;
  429.    }
  430.  
  431.    // $FF: synthetic method
  432.    static URL access$1700(String var0) {
  433.       return getImageResource(var0);
  434.    }
  435.  
  436.    // $FF: synthetic method
  437.    static void access$1800(AbstractButton var0, Container var1, ButtonGroup var2) {
  438.       addToBG(var0, var1, var2);
  439.    }
  440.  
  441.    static {
  442.       initResource();
  443.    }
  444. }
  445.